Title: SQL W3S (By-BKK) / 104 Create Table
Tags: Obsidian_to_Anki

Q: What is the purpose of the SQL CREATE TABLE statement?
A: To create a new table in a database

Q: True or False: The CREATE TABLE statement is used to insert data into a table.
A: False

Q: What does the 'datatype' parameter specify in CREATE TABLE?
A: The type of data a column can hold (e.g., varchar, int, date)

Q: How do you specify a column when creating a table?
A: By stating its name and datatype

Q: Give an example SQL statement to create a table called Persons with columns for ID, LastName, FirstName, Address, and City.
A: CREATE TABLE Persons (PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255));

Q: What does varchar(255) mean in a CREATE TABLE statement?
A: A column that holds text data up to 255 characters

Q: True or False: The PersonID column in the example is an integer type.
A: True

Q: Fill in the blank: To fill a new table with data, use the SQL statement.
A: INSERT INTO

Q: What will the structure of an empty Persons table look like?
A: Columns for PersonID, LastName, FirstName, Address, City; no rows

Q: Reverse: CREATE TABLE Persons (PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255));
A: Give an example SQL statement to create a table called Persons with columns for ID, LastName, FirstName, Address, and City.

Q: How can you create a new table as a copy of an existing table?
A: Use CREATE TABLE new_table AS SELECT … FROM existing_table

Q: True or False: You can create a new table with all or specific columns from another table using CREATE TABLE … AS SELECT.
A: True

Q: What does the following SQL command do? CREATE TABLE TestTable AS SELECT customername, contactname FROM customers;
A: Creates a new table TestTable with the specified columns and their data copied from customers

Q: Reverse: Creates a new table TestTable with the specified columns and their data copied from customers
A: What does the following SQL command do? CREATE TABLE TestTable AS SELECT customername, contactname FROM customers;